const express = require("express");
let app = express();
const fs = require("fs");
let data = JSON.parse(fs.readFileSync("./data.json", "utf-8"));
app.get("/", (req, res) => {
  let str = `<ul>`;
  data.forEach((item) => {
    str += `<li><a href="/showDetail/${item.id}">${item.title}</a></li>`;
  });
  str += `</ul>`;
  res.send(str);
});
app.get("/showDetail/:id", (req, res) => {
  let centent = ``;
  data.forEach((item) => {
    if (req.params.id == item.id) {
      centent = `<p>${item.content}</p>`;
    }
  });
  res.send(centent);
});
app.listen(9899);
